#!/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'

from PySide import QtGui, QtCore

class SubmitBtn(QtGui.QPushButton):
    def __init__(self, text='',  parent=None):
        super(SubmitBtn, self).__init__( parent=parent)
        self._text = text
        self.setCheckable(0)
        main_layout = QtGui.QHBoxLayout(self)
        self.customText = QtGui.QLabel(text)
        self.customText.setStyleSheet("background:rgba(0,0,0,0)")
        main_layout.addItem(QtGui.QSpacerItem(0,0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
        main_layout.addWidget(self.customText)
        main_layout.addItem(QtGui.QSpacerItem(0,0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
        main_layout.setContentsMargins(0,0,0,0)
        main_layout.setSpacing(0)
        self.customText.setAlignment(QtCore.Qt.AlignCenter)
        self.updateCustomText(0)
        self.customText.mouseReleaseEvent = self.customClicked
        
    def customClicked(self, event):
        self.mouseReleaseEvent(event)
        
    def updateCustomText(self, text):
        if self._text:
            if int(text) == 0:
                color = 'red'
            else:
                color = 'rgb(0,255,0)'
            self.customText.setText('<html><head/><body>%s ( <span style="color:%s;">%s</span> )</body></html>' %(self._text, color, text))
            
            
if __name__ == "__main__":
    app = QtGui.QApplication([])
    bmui = SubmitBtn()
    bmui.show()
    app.exec_()